home *** CD-ROM | disk | FTP | other *** search
- #include "maker.h"
- #include "proto.h"
-
- #include <graphics/gfxmacros.h>
-
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #include <proto/exec.h>
-
- #include <math.h>
- #include <string.h>
-
-
- BOOL PtinRect(Point *pt, Rect *rect)
- {
- if ( (pt->x >= rect->minX) &&
- (pt->x <= rect->maxX) &&
- (pt->y >= rect->minY) &&
- (pt->y <= rect->maxY) )
- return TRUE;
- else
- return FALSE;
- }
-
- BOOL PtbyLine(Point *pt, Rect *rect, short tol)
- {
- double m, b;
- short xf, yf, dx, dy;
- long d2;
-
- /* Check for the infinite slope case */
-
- if (rect->minX == rect->maxX)
- {
- dx = abs(pt->x - rect->minX);
- if (dx < tol)
- return TRUE;
- }
- else
- {
-
- m = (double) (rect->minY - rect->maxY) /
- (double) (rect->minX - rect->maxX);
- b = rect->minY - m * rect->minX;
-
- xf = (pt->x - m * b + m * pt->y) / (m * m + 1.0) + 0.5;
-
- if ( (rect->minX < rect->maxX && rect->minX <= xf &&
- xf <= rect->maxX) ||
- (rect->minX > rect->maxX && rect->minX >= xf &&
- xf >= rect->maxX))
- {
- yf = m * xf + b + 0.5;
- dx = xf - pt->x;
- dy = yf - pt->y;
- d2 = (long) dx * dx + (long) dy * dy;
- if (d2 < tol * tol)
- return TRUE;
- }
- }
-
- return FALSE;
- }
-
- BOOL DragRect(register Window *window, register Point *mouse, register Rect *rect)
- {
- short poly[8],x,y,dx,dy,lastx,lasty,code,xmin,xmax,ymin,ymax;
- struct RastPort *rp;
- ULONG class, flags;
- Rect tempRect;
-
- short bordleft, bordtop, bordright, bordbottom;
- /*
- UBYTE mask;
- */
- struct IntuiMessage *message;
-
- bordleft = window->BorderLeft;
- bordright = window->BorderRight;
- bordtop = window->BorderTop;
- bordbottom = window->BorderBottom;
-
- rp = window->RPort;
- /*
- mask = rp->Mask;
- rp->Mask = 0x01;
- */
- xmin = rect->minX;
- xmax = rect->maxX;
- ymin = rect->minY;
- ymax = rect->maxY;
-
- poly[0] = xmax; poly[1] = ymin;
- poly[2] = xmax; poly[3] = ymax;
- poly[4] = xmin; poly[5] = ymax;
- poly[6] = xmin; poly[7] = ymin;
-
- lastx = mouse->x;
- lasty = mouse->y;
-
- flags = window->IDCMPFlags;
- ModifyIDCMP(window, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE /* IDCMP_INTUITICKS */ );
-
- SetDrMd(rp, COMPLEMENT);
- SetDrPt(rp, DASH);
- Move(rp, xmin, ymin);
- PolyDraw(rp, 4L, poly);
-
- FOREVER
- {
- while (message = (struct IntuiMessage *)
- GetMsg(window->UserPort))
- {
- class = message->Class;
- code = message->Code;
- x = message->MouseX;
- y = message->MouseY;
- ReplyMsg((struct Message *) message);
- switch(class)
- {
- case IDCMP_MOUSEBUTTONS:
- if (code == SELECTUP)
- {
- rect->minX = poly[6];
- rect->minY = poly[7];
- rect->maxX = poly[2];
- rect->maxY = poly[3];
-
- Move(rp,poly[6],poly[7]);
- PolyDraw(rp,4,poly);
-
- SetDrMd(rp, JAM1);
- SetDrPt(rp, SOLID);
-
- ModifyIDCMP(window, flags);
- /*
- rp->Mask = mask;
- */
- if (xmin == rect->minX && ymin == rect->minY)
- return FALSE;
- else
- return TRUE;
- }
- break;
-
- /* case IDCMP_INTUITICKS: */
-
- case IDCMP_MOUSEMOVE:
-
- if (x < mouse->x - xmin + bordleft)
- x = mouse->x - xmin + bordleft;
- else if (window->Width - 1 - bordright - x <
- xmax - mouse->x)
- x = window->Width - 1 - bordright - (xmax - mouse->x);
- if (y < mouse->y - ymin + bordtop)
- y = mouse->y - ymin + bordtop;
- else if (window->Height - 1 - bordbottom - y <
- ymax - mouse->y)
- y = window->Height - 1 - bordbottom - (ymax - mouse->y);
-
- if (x != lastx || y != lasty)
- {
- Move(rp,poly[6],poly[7]);
- PolyDraw(rp,4,poly);
- dx = x - lastx;
- dy = y - lasty;
- poly[0] += dx;
- poly[2] += dx;
- poly[4] += dx;
- poly[6] += dx;
- poly[1] += dy;
- poly[3] += dy;
- poly[5] += dy;
- poly[7] += dy;
- Move(rp,poly[6],poly[7]);
- Draw(rp,poly[0],poly[1]);
- Draw(rp,poly[2],poly[3]);
- Draw(rp,poly[4],poly[5]);
- Draw(rp,poly[6],poly[7]);
- /*
- PolyDraw(rp,4,poly);
- */
- lastx = x;
- lasty = y;
-
- // update the information window
-
- tempRect.minX = poly[6];
- tempRect.minY = poly[7];
- tempRect.maxX = poly[2];
- tempRect.maxY = poly[3];
-
- UpdateInfoWindow(&tempRect);
- }
- break;
- default:
- break;
- }
- }
- /*
- wait only if the already available messages did not satisfy the request
- */
- Wait(1<<window->UserPort->mp_SigBit);
- }
- }
-
- BOOL DragLine(register Window *window, register Point *mouse, register Rect *rect)
- {
- short cpx1, cpx2, cpy1, cpy2, x, y, dx, dy, lastx, lasty;
- short code,xmin,xmax,ymin,ymax;
- struct RastPort *rp;
- ULONG class,flags;
- struct IntuiMessage *message;
-
- short bordleft, bordtop, bordright, bordbottom;
- bordleft = window->BorderLeft;
- bordright = window->BorderRight;
- bordtop = window->BorderTop;
- bordbottom = window->BorderBottom;
-
- rp = window->RPort;
-
- xmin = rect->minX;
- xmax = rect->maxX;
- ymin = rect->minY;
- ymax = rect->maxY;
-
- cpx1 = xmin;
- cpy1 = ymin;
- cpx2 = xmax;
- cpy2 = ymax;
-
- lastx = mouse->x;
- lasty = mouse->y;
-
- flags = window->IDCMPFlags;
- ModifyIDCMP(window, MOUSEBUTTONS | INTUITICKS);
-
- SetDrMd(rp, COMPLEMENT);
- SetDrPt(rp, DASH);
- Move(rp, xmin, ymin);
- Draw(rp, xmax, ymax);
-
- FOREVER
- {
- while (message = (struct IntuiMessage *)
- GetMsg(window->UserPort))
- {
- class = message->Class;
- code = message->Code;
- x = message->MouseX;
- y = message->MouseY;
- ReplyMsg((struct Message *) message);
- switch(class)
- {
- case MOUSEBUTTONS:
- if (code == SELECTUP)
- {
- rect->minX = cpx1;
- rect->minY = cpy1;
- rect->maxX = cpx2;
- rect->maxY = cpy2;
-
- Move(rp, cpx1, cpy1);
- Draw(rp, cpx2, cpy2);
-
- SetDrMd(rp, JAM1);
- SetDrPt(rp, SOLID);
-
- ModifyIDCMP(window, flags);
-
- if (xmin == rect->minX && ymin == rect->minY)
- return FALSE;
- else
- return TRUE;
- }
- break;
-
- case INTUITICKS:
- if (xmin < xmax)
- {
- if (x < mouse->x - xmin + bordleft)
- x = mouse->x - xmin + bordleft;
- else if (window->Width - 1 - bordright - x <
- xmax - mouse->x)
- x = window->Width - 1 - bordright - (xmax - mouse->x);
- }
- else
- {
- if (x < mouse->x - xmax + bordleft)
- x = mouse->x - xmax + bordleft;
- else if (window->Width - 1 - bordright - x <
- xmin - mouse->x)
- x = window->Width - 1 - bordright -
- (xmin - mouse->x);
- }
-
- if (ymin < ymax)
- {
- if (y < mouse->y - ymin + bordtop)
- y = mouse->y - ymin + bordtop;
- else if (window->Height - 1 - bordbottom - y <
- ymax - mouse->y)
- y = window->Height - 1 - bordbottom - (ymax - mouse->y);
- }
- else
- {
- if (y < mouse->y - ymax + bordtop)
- y = mouse->y - ymax + bordtop;
- else if (window->Height - 1 - bordbottom - y <
- ymin - mouse->y)
- y = window->Height - 1 - bordbottom -
- (ymin - mouse->y);
- }
-
- if (x != lastx || y != lasty)
- {
- Move(rp, cpx1, cpy1);
- Draw(rp, cpx2, cpy2);
- dx = x - lastx;
- dy = y - lasty;
- cpx1 += dx;
- cpy1 += dy;
- cpx2 += dx;
- cpy2 += dy;
-
- Move(rp, cpx1, cpy1);
- Draw(rp, cpx2, cpy2);
-
- lastx = x;
- lasty = y;
- }
- break;
- default:
- break;
- }
- }
- /*
- wait only if the already available messages did not satisfy the request
- */
- Wait(1<<window->UserPort->mp_SigBit);
- }
- }
-
- BOOL SizeLine(register Window *window, register Point *mouse, Point *start, Point *anchor)
- {
- short cpx1, cpy1, x, y, dx, dy, lastx, lasty, code;
- struct RastPort *rp;
- ULONG class, flags;
- struct IntuiMessage *message;
-
- short bordleft, bordtop, bordright, bordbottom;
- bordleft = window->BorderLeft;
- bordright = window->BorderRight;
- bordtop = window->BorderTop;
- bordbottom = window->BorderBottom;
-
- rp = window->RPort;
-
- cpx1 = start->x;
- cpy1 = start->y;
-
- lastx = mouse->x;
- lasty = mouse->y;
-
- flags = window->IDCMPFlags;
- ModifyIDCMP(window, MOUSEBUTTONS | INTUITICKS);
-
- SetDrMd(rp, COMPLEMENT);
- SetDrPt(rp, DASH);
- Move(rp, start->x, start->y);
- Draw(rp, anchor->x, anchor->y);
-
- FOREVER
- {
- while (message = (struct IntuiMessage *)
- GetMsg(window->UserPort))
- {
- class = message->Class;
- code = message->Code;
- x = message->MouseX;
- y = message->MouseY;
- ReplyMsg((struct Message *) message);
- switch(class)
- {
- case MOUSEBUTTONS:
- if (code == SELECTUP)
- {
- start->x = cpx1;
- start->y = cpy1;
-
- Move(rp, cpx1, cpy1);
- Draw(rp, anchor->x, anchor->y);
-
- SetDrMd(rp, JAM1);
- SetDrPt(rp, SOLID);
-
- ModifyIDCMP(window, flags);
-
- if (start->x == cpx1 && start->y == cpy1)
- return FALSE;
- else
- return TRUE;
- }
- break;
-
- case INTUITICKS:
-
- if (x < mouse->x - start->x + bordleft)
- x = mouse->x - start->x + bordleft;
- else if (window->Width - 1 - bordright - x <
- start->x - mouse->x)
- x = window->Width - 1 - bordright -
- (start->x - mouse->x);
- if (y < mouse->y - start->y + bordtop)
- y = mouse->y - start->y + bordtop;
- else if (window->Height - 1 - bordbottom - y <
- start->y - mouse->y)
- y = window->Height - 1 - bordbottom -
- (start->y - mouse->y);
-
- if (x != lastx || y != lasty)
- {
- Move(rp, cpx1, cpy1);
- Draw(rp, anchor->x, anchor->y);
- dx = x - lastx;
- dy = y - lasty;
- cpx1 += dx;
- cpy1 += dy;
-
- Move(rp, cpx1, cpy1);
- Draw(rp, anchor->x, anchor->y);
-
- lastx = x;
- lasty = y;
- }
- break;
- default:
- break;
- }
- }
- /*
- wait only if the already available messages did not satisfy the request
- */
- Wait(1<<window->UserPort->mp_SigBit);
- }
- }
-
- BOOL DragPoly(register Window *window, register Point *mouse, short npts, register short *points)
- {
- short *poly, x, y, dx, dy, lastx, lasty, code,
- xmin, xmax, ymin, ymax, *temp, i;
- struct RastPort *rp;
- ULONG class,flags;
- BOOL flag;
- /*
- UBYTE mask;
- */
- struct IntuiMessage *message;
-
- short bordleft, bordtop, bordright, bordbottom;
- bordleft = window->BorderLeft;
- bordright = window->BorderRight;
- bordtop = window->BorderTop;
- bordbottom = window->BorderBottom;
-
- if (!npts)
- return FALSE;
- if (!GetMem((void **) &poly, (long) npts * sizeof(short)))
- return FALSE;
-
- memcpy((char *) poly, (char *) points, (int) npts * sizeof(short));
-
- rp = window->RPort;
- /*
- mask = rp->Mask;
- rp->Mask = 0x01;
- */
- /*
- Find the minima and maxima of the vertices
- */
- xmin = 30000;
- xmax = 0;
- ymin = 30000;
- ymax = 0;
- temp = poly;
- for (i=0; i<npts; i++)
- {
- if (*temp < xmin)
- xmin = *temp;
- else if (*temp > xmax)
- xmax = *temp;
-
- temp++;
- if (*temp < ymin)
- ymin = *temp;
- else if (*temp > ymax)
- ymax = *temp;
-
- temp++;
- }
-
- lastx = mouse->x;
- lasty = mouse->y;
-
- flags = window->IDCMPFlags;
- ModifyIDCMP(window, MOUSEBUTTONS | INTUITICKS);
-
- SetDrMd(rp, COMPLEMENT);
- SetDrPt(rp, DASH);
- Move(rp, poly[0], poly[1]);
- PolyDraw(rp, (long) npts, poly);
-
- FOREVER
- {
- while (message = (struct IntuiMessage *)
- GetMsg(window->UserPort))
- {
- class = message->Class;
- code = message->Code;
- x = message->MouseX;
- y = message->MouseY;
- ReplyMsg((struct Message *) message);
-
- switch(class)
- {
- case MOUSEBUTTONS:
- if (code == SELECTUP)
- {
- if (poly[0] == points[0] && poly[1] == points[1])
- flag = FALSE;
- else
- flag = TRUE;
- memcpy((char *) poly, (char *) points,
- (int) npts * sizeof(short));
- Move(rp, poly[0], poly[1]);
- PolyDraw(rp, (long) npts, poly);
-
- SetDrMd(rp, JAM1);
- SetDrPt(rp, SOLID);
-
- ModifyIDCMP(window, flags);
- /*
- rp->Mask = mask;
- */
- DropMem( (void **) &poly, (long) npts * sizeof(short));
-
- return flag;
- }
- break;
-
- case INTUITICKS:
-
- if (x < mouse->x - xmin + bordleft)
- x = mouse->x - xmin + bordleft;
- else if (window->Width - 1 - bordright - x <
- xmax - mouse->x)
- x = window->Width - 1 - bordright - (xmax - mouse->x);
- if (y < mouse->y - ymin + bordtop)
- y = mouse->y - ymin + bordtop;
- else if (window->Height - 1 - bordbottom - y <
- ymax - mouse->y)
- y = window->Height - 1 - bordbottom - (ymax - mouse->y);
-
- if (x != lastx || y != lasty)
- {
- Move(rp, poly[0], poly[1]);
- PolyDraw(rp, (long) npts, poly);
- dx = x - lastx;
- dy = y - lasty;
- temp = poly;
-
- for (i=0; i<npts; i++)
- {
- *temp++ += dx;
- *temp++ += dy;
- }
- Move(rp, poly[0], poly[1]);
- PolyDraw(rp, (long) npts, poly);
-
- lastx = x;
- lasty = y;
- }
- break;
- default:
- break;
- }
- }
- /*
- wait only if the already available messages did not satisfy the request
- */
- Wait(1<<window->UserPort->mp_SigBit);
- }
- }
-
- /*******************************************************************************************/
-
- BOOL SizeRect(register Window *window, register Point *mouse, register Rect *rect,
- Point *minsize, Point *maxsize)
- {
- short poly[8], x, y, dx, dy, lastx, lasty, code, xmin, xmax, ymin, ymax;
- RastPort *rp;
- ULONG class,flags;
- IntuiMessage *message;
- Rect tempRect;
-
- short bordleft, bordtop, bordright, bordbottom;
-
- bordleft = window->BorderLeft;
- bordright = window->BorderRight;
- bordtop = window->BorderTop;
- bordbottom = window->BorderBottom;
-
- rp = window->RPort;
-
- xmin = rect->minX;
- xmax = rect->maxX;
- ymin = rect->minY;
- ymax = rect->maxY;
-
- poly[0] = xmax; poly[1] = ymin;
- poly[2] = xmax; poly[3] = ymax;
- poly[4] = xmin; poly[5] = ymax;
- poly[6] = xmin; poly[7] = ymin;
-
- lastx = mouse->x;
- lasty = mouse->y;
-
- flags = window->IDCMPFlags;
- ModifyIDCMP(window, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE /* INTUITICKS */);
-
- SetDrMd(rp, COMPLEMENT);
- SetDrPt(rp, DASH);
- Move(rp, xmin, ymin);
- PolyDraw(rp, 4, poly);
-
- FOREVER
- {
- while (message = (IntuiMessage *) GetMsg(window->UserPort))
- {
- class = message->Class;
- code = message->Code;
- x = message->MouseX;
- y = message->MouseY;
- ReplyMsg((Message *) message);
- switch(class)
- {
- case IDCMP_MOUSEBUTTONS:
- if (code == SELECTUP)
- {
- Move(rp, poly[6], poly[7]);
- PolyDraw(rp, 4, poly);
-
- SetDrMd(rp, JAM1);
- SetDrPt(rp, SOLID);
-
- ModifyIDCMP(window, flags);
-
- if (poly[2] == xmax && poly[3] == ymax)
- return FALSE;
-
- rect->maxX = poly[2];
- rect->maxY = poly[3];
-
- return TRUE;
- }
- break;
- /* case IDCMP_INTUITICKS: */
- case IDCMP_MOUSEMOVE:
-
- if (x - xmin < minsize->x)
- x = xmin + minsize->x;
- else if (x - xmin > maxsize->x)
- x = xmin + maxsize->x;
- if (y - ymin < minsize->y)
- y = ymin + minsize->y;
- else if (y - ymin > maxsize->y)
- y = ymin + maxsize->y;
-
- if (window->Width - 1 - bordright - x < xmax - mouse->x)
- x = window->Width - 1 - bordright - (xmax - mouse->x);
- if (window->Height - 1 - bordbottom - y < ymax - mouse->y)
- y = window->Height - 1 - bordbottom - (ymax - mouse->y);
-
- if (x != lastx || y != lasty)
- {
- Move(rp, poly[6], poly[7]);
- PolyDraw(rp, 4, poly);
- dx = x - lastx;
- dy = y - lasty;
- poly[0] += dx;
- poly[2] += dx;
- poly[3] += dy;
- poly[5] += dy;
- Move(rp,poly[6],poly[7]);
- PolyDraw(rp,4,poly);
- lastx = x;
- lasty = y;
-
- // update the information window
-
- tempRect.minX = poly[6];
- tempRect.minY = poly[7];
- tempRect.maxX = poly[2];
- tempRect.maxY = poly[3];
-
- UpdateInfoWindow(&tempRect);
- }
- break;
- default:
- break;
- }
- }
- /*
- wait only if the already available messages did not satisfy the request
- */
- Wait(1<<window->UserPort->mp_SigBit);
- }
- }
-
-
-